package cn.ryh.sentinel.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * @author Rao
 * @Description
 * @create 2021-12-16 17:49
 */
@RestController
public class SendMessageController {
    @Resource
    private RestTemplate restTemplate;

    @Value("${service-url.nacos-user-service}")
    private String serverURL;

    @GetMapping(value = "/consumer/payment/nacos/{id}")
    public String paymentInfo(@PathVariable("id") Long id) throws InterruptedException {
        long l = 10 / id;
        return restTemplate.getForObject(serverURL + "/payment/nacos/" + id, String.class);
    }

    @GetMapping("/config/info")
    public String getConfigInfo() {
        return restTemplate.getForObject(serverURL + "/config/info", String.class);
    }

    @GetMapping("/testHotKey/{id}")
    @SentinelResource(value = "testHotKey",blockHandler = "deal_testHotKey")
    public String testHotKey(@PathVariable("id") Long id) {
        //int age = 10/0;
        return "------testHotKey";
    }

    //兜底方法
    public String deal_testHotKey (Long id, BlockException exception){
        return "------deal_testHotKey,o(╥﹏╥)o";
    }
}
